package one.bugu.android.demon.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Created Date 2018/1/22
 * Time: 10:14
 * Description:
 */
public class BigDecimalUtil {


    public static String formatMoney(String money){
        try {
            return BigDecimal.valueOf(Double.parseDouble(money)).setScale(2, RoundingMode.DOWN).doubleValue()+"";
        } catch (Exception e) {
            e.printStackTrace();
            return "0.00";
        }
    }

    public static double formatMoneyToDouble(String money){
        try {
            return BigDecimal.valueOf(Double.parseDouble(money)).setScale(2, RoundingMode.DOWN).doubleValue();
        } catch (Exception e) {
            e.printStackTrace();
            return 0.00;
        }
    }



    public static String formatMoney(double money){
        try {
            return BigDecimal.valueOf(money).setScale(2, RoundingMode.DOWN).doubleValue()+"";
        } catch (Exception e) {
            e.printStackTrace();
            return "0.00";
        }
    }

    public static String formatFourMoney(double money){
        try {
            return BigDecimal.valueOf(money).setScale(4, RoundingMode.DOWN).doubleValue()+"";
        } catch (Exception e) {
            e.printStackTrace();
            return "0.00";
        }
    }


    public static double formatMoneyToDouble(double money){
        try {
            return BigDecimal.valueOf(money).setScale(2, RoundingMode.DOWN).doubleValue();
        } catch (Exception e) {
            e.printStackTrace();
            return 0.00;
        }
    }
}
